<template>
    <a-drawer
        :title="formData.kkdm ? '编辑教学任务' : '增加教学任务'"
        :width="600"
        :visible="visible"
        :destroy-on-close="true"
        :footer-style="{ textAlign: 'right' }"
        @close="onClose"
    >
        <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
            <a-form-item label="学年学期：" name="xnxq01id">
                <a-input v-model:value="formData.xnxq01id" placeholder="请输入学年学期" allow-clear />
            </a-form-item>
            <a-form-item label="开课学年：" name="kkxn">
                <a-input v-model:value="formData.kkxn" placeholder="请输入开课学年" allow-clear />
            </a-form-item>
            <a-form-item label="开课学期：" name="kkxq">
                <a-input v-model:value="formData.kkxq" placeholder="请输入开课学期" allow-clear />
            </a-form-item>
            <a-form-item label="上课班级代码：" name="skbjdm">
                <a-input v-model:value="formData.skbjdm" placeholder="请输入上课班级代码" allow-clear />
            </a-form-item>
            <a-form-item label="上课班级名称：" name="skbjmc">
                <a-input v-model:value="formData.skbjmc" placeholder="请输入上课班级名称" allow-clear />
            </a-form-item>
            <a-form-item label="上课班级年级：" name="sknj">
                <a-input v-model:value="formData.sknj" placeholder="请输入上课班级年级" allow-clear />
            </a-form-item>
            <a-form-item label="专业代码：" name="skzydm">
                <a-input v-model:value="formData.skzydm" placeholder="请输入专业代码" allow-clear />
            </a-form-item>
            <a-form-item label="专业名称：" name="skzymc">
                <a-input v-model:value="formData.skzymc" placeholder="请输入专业名称" allow-clear />
            </a-form-item>
            <a-form-item label="课程代码：" name="kcdm">
                <a-input v-model:value="formData.kcdm" placeholder="请输入课程代码" allow-clear />
            </a-form-item>
            <a-form-item label="课程名称：" name="kcmc">
                <a-input v-model:value="formData.kcmc" placeholder="请输入课程名称" allow-clear />
            </a-form-item>
            <a-form-item label="总学时：" name="zxs">
                <a-input v-model:value="formData.zxs" placeholder="请输入总学时" allow-clear />
            </a-form-item>
            <a-form-item label="学分：" name="xf">
                <a-input v-model:value="formData.xf" placeholder="请输入学分" allow-clear />
            </a-form-item>
            <a-form-item label="课程性质代码：" name="kcxzdm">
                <a-input v-model:value="formData.kcxzdm" placeholder="请输入课程性质代码" allow-clear />
            </a-form-item>
            <a-form-item label="课程性质名称：" name="kcxzmc">
                <a-input v-model:value="formData.kcxzmc" placeholder="请输入课程性质名称" allow-clear />
            </a-form-item>
            <a-form-item label="课程属性代码：" name="kcsxdm">
                <a-input v-model:value="formData.kcsxdm" placeholder="请输入课程属性代码" allow-clear />
            </a-form-item>
            <a-form-item label="课程属性名称：" name="kcsxmc">
                <a-input v-model:value="formData.kcsxmc" placeholder="请输入课程属性名称" allow-clear />
            </a-form-item>
            <a-form-item label="课程类别代码：" name="kclbdm">
                <a-input v-model:value="formData.kclbdm" placeholder="请输入课程类别代码" allow-clear />
            </a-form-item>
            <a-form-item label="课程类别名称：" name="kclbmc">
                <a-input v-model:value="formData.kclbmc" placeholder="请输入课程类别名称" allow-clear />
            </a-form-item>
            <a-form-item label="开课单位代码：" name="kkdwdm">
                <a-input v-model:value="formData.kkdwdm" placeholder="请输入开课单位代码" allow-clear />
            </a-form-item>
            <a-form-item label="开课单位：" name="kkdwmc">
                <a-input v-model:value="formData.kkdwmc" placeholder="请输入开课单位" allow-clear />
            </a-form-item>
            <a-form-item label="校区代码：" name="kkxqdm">
                <a-input v-model:value="formData.kkxqdm" placeholder="请输入校区代码" allow-clear />
            </a-form-item>
            <a-form-item label="校区名称：" name="kkxqmc">
                <a-input v-model:value="formData.kkxqmc" placeholder="请输入校区名称" allow-clear />
            </a-form-item>
            <a-form-item label="合班名称：" name="hbmc">
                <a-input v-model:value="formData.hbmc" placeholder="请输入合班名称" allow-clear />
            </a-form-item>
            <a-form-item label="分组名：" name="fzmc">
                <a-input v-model:value="formData.fzmc" placeholder="请输入分组名" allow-clear />
            </a-form-item>
            <a-form-item label="选课人数：" name="xdrs">
                <a-input v-model:value="formData.xdrs" placeholder="请输入选课人数" allow-clear />
            </a-form-item>
            <a-form-item label="人数系数：" name="xkrsxd">
                <a-input v-model:value="formData.xkrsxd" placeholder="请输入人数系数" allow-clear />
            </a-form-item>
            <a-form-item label="上课教师工号：" name="skjsjgh">
                <a-input v-model:value="formData.skjsjgh" placeholder="请输入上课教师工号" allow-clear />
            </a-form-item>
            <a-form-item label="上课教师名称：" name="skjsmc">
                <a-input v-model:value="formData.skjsmc" placeholder="请输入上课教师名称" allow-clear />
            </a-form-item>
            <a-form-item label="上课周次：" name="skzc">
                <a-input v-model:value="formData.skzc" placeholder="请输入上课周次" allow-clear />
            </a-form-item>
            <a-form-item label="上课时间：" name="sksj">
                <a-input v-model:value="formData.sksj" placeholder="请输入上课时间" allow-clear />
            </a-form-item>
            <a-form-item label="上课地点：" name="skdd">
                <a-input v-model:value="formData.skdd" placeholder="请输入上课地点" allow-clear />
            </a-form-item>
            <a-form-item label="课程英文名称：" name="kcywmc">
                <a-input v-model:value="formData.kcywmc" placeholder="请输入课程英文名称" allow-clear />
            </a-form-item>
            <a-form-item label="是否停课：" name="sftk">
                <a-input v-model:value="formData.sftk" placeholder="请输入是否停课" allow-clear />
            </a-form-item>
            <a-form-item label="课程状态：" name="kczt">
                <a-input v-model:value="formData.kczt" placeholder="请输入课程状态" allow-clear />
            </a-form-item>
            <a-form-item label="周学时：" name="zzxs">
                <a-input v-model:value="formData.zzxs" placeholder="请输入周学时" allow-clear />
            </a-form-item>
            <a-form-item label="理论学时：" name="llxs">
                <a-input v-model:value="formData.llxs" placeholder="请输入理论学时" allow-clear />
            </a-form-item>
            <a-form-item label="实验学时：" name="syxs">
                <a-input v-model:value="formData.syxs" placeholder="请输入实验学时" allow-clear />
            </a-form-item>
            <a-form-item label="实践学时：" name="sjxs">
                <a-input v-model:value="formData.sjxs" placeholder="请输入实践学时" allow-clear />
            </a-form-item>
            <a-form-item label="其它学时：" name="qtxs">
                <a-input v-model:value="formData.qtxs" placeholder="请输入其它学时" allow-clear />
            </a-form-item>
            <a-form-item label="教材名称：" name="jcmc">
                <a-input v-model:value="formData.jcmc" placeholder="请输入教材名称" allow-clear />
            </a-form-item>
            <a-form-item label="是否学位课：" name="sfxwk">
                <a-input v-model:value="formData.sfxwk" placeholder="请输入是否学位课" allow-clear />
            </a-form-item>
            <a-form-item label="考试方式名称：" name="ksfsmc">
                <a-input v-model:value="formData.ksfsmc" placeholder="请输入考试方式名称" allow-clear />
            </a-form-item>
            <a-form-item label="考试方式代码：" name="ksfs">
                <a-input v-model:value="formData.ksfs" placeholder="请输入考试方式代码" allow-clear />
            </a-form-item>
        </a-form>
        <template #footer>
            <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
            <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
        </template>
    </a-drawer>
</template>

<script setup name="jwJxrwForm">
    import { cloneDeep } from 'lodash-es'
    import { required } from '@/utils/formRules'
    import jwJxrwApi from '@/api/biz/jwJxrwApi'
    // 抽屉状态
    const visible = ref(false)
    const emit = defineEmits({ successful: null })
    const formRef = ref()
    // 表单数据
    const formData = ref({})
    const submitLoading = ref(false)

    // 打开抽屉
    const onOpen = (record) => {
        visible.value = true
        if (record) {
            let recordData = cloneDeep(record)
            formData.value = Object.assign({}, recordData)
        }
    }
    // 关闭抽屉
    const onClose = () => {
        formRef.value.resetFields()
        formData.value = {}
        visible.value = false
    }
    // 默认要校验的
    const formRules = {
    }
    // 验证并提交数据
    const onSubmit = () => {
        formRef.value
            .validate()
            .then(() => {
                submitLoading.value = true
                const formDataParam = cloneDeep(formData.value)
                jwJxrwApi
                    .jwJxrwSubmitForm(formDataParam, formDataParam.kkdm)
                    .then(() => {
                        onClose()
                        emit('successful')
                    })
                    .finally(() => {
                        submitLoading.value = false
                    })
            })
    }
    // 抛出函数
    defineExpose({
        onOpen
    })
</script>
